
var map = document.getElementById('map');
var game = new Game(map);
var speed = 150;
// window.
var btn1 = document.querySelector(".btn1");
var btn2 = document.querySelector(".btn2");
var btn3 = document.querySelector(".btn3");
var btn4 = document.querySelector(".btn4");
var btn5 = document.querySelector(".btn5");
var btn6 = document.querySelector(".btn6");
var btn7 = document.querySelector(".btn7");
btn1.addEventListener("click", function () {
  var r = Tools.getRandom(0, 255);
  var g = Tools.getRandom(0, 255);
  var b = Tools.getRandom(0, 255);
  // 将生成的随机颜色,设置为小方块
  map.style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')';
})
btn2.addEventListener("click", function () {
  game.start();
  this.disabled = true;
})
btn3.addEventListener("click", function () {
  clearInterval(Game.timerId);
  btn2.disabled = false;
})
btn4.addEventListener("click", function () {
  clearInterval(Game.timerId);
  speed -= 10;
  runSnake(speed);
  this.innerText = "加速 " + speed + "ms";
  btn5.innerText = "减速";
})
btn5.addEventListener("click", function () {
  clearInterval(Game.timerId);
  speed += 10;
  runSnake(speed);
  btn4.innerText = "加速";
  this.innerText = "减速 " + speed + "ms";
})
btn6.addEventListener("click", function () {
  location.reload(true);
})
btn7.addEventListener("click", function () {
  for (let i = 1; i < game.snake.body.length; i++) {
    var r = Tools.getRandom(0, 255);
    var g = Tools.getRandom(0, 255);
    var b = Tools.getRandom(0, 255);
    game.snake.body[i].color = 'rgb(' + r + ',' + g + ',' + b + ')';

  }
})